package com.cn.dream_order_server.util;

import com.sun.org.apache.bcel.internal.generic.RETURN;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;

public class RandomGenUtil {

    //生成不重复的订单号
    public static String fourRandomGenOrderId(){
        //生成时间规则
        SimpleDateFormat format = new SimpleDateFormat("yyyyMMddHHmmss");
        return "D"+format.format(new Date())+fourRandomGen();
    }



    //生成思维不重复的验证码
    private static String fourRandomGen(){
        char[] chars={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z','0','1','2','3','4','5','6','7','8','9'};
        Random random=new Random();
        int count=0;

        StringBuilder sb=new StringBuilder();//动态字符串

        while(true){
            char c=chars[random.nextInt(chars.length)];

            if(sb.indexOf(c+"")==-1){
                sb.append(c);
                count++;
                if(count==4){
                    break;
                }
            }

        }
        return sb.toString();
    }



}
